from twisted.cred import error, credentials
from twisted.internet import defer

from option import Option

class CredentialChecker:
	credentialInterfaces = (credentials.IUsernamePassword,
			credentials.IUsernameHashedPassword,
			)
	def __init__(self):
		self.users = { 'admin' : 'ppp', 'emce' : 'mc', 'matthew23' : 'zbll'}

	def cbPasswordMatch(self, matched, username):
		if matched:
			return username
		else:
			return defer.fail(error.UnauthorizedLogin())

	def requestAvatarId(self, credentials):
		if credentials.username in self.users and not credentials.username in Option().users:
			return defer.maybeDeferred(credentials.checkPassword, self.users[credentials.username]).addCallback(self.cbPasswordMatch, credentials.username)
		else:
			return defer.fail(error.UnauthorizedLogin())
				

